#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Purpose: Symbol tests
# Created: 02/02/2009
# $Id $
# Copyright (c) 2008,2009 by University College London
# Authors:
# Didrik Pinte --<dpinte@dipole-consulting.com>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with HydroPlatform for details.

import unittest
import wx

import support
support.init_hydroplatform()


from hydroplatform.ui import renderer

class SymbolTest(unittest.TestCase):
   
    def setUp(self):
        self.app = wx.PySimpleApp()
        session = support.get_dbsession()
        support.load_sample_network1(session)

    def test_draw_triangle(self):
        self.bmp = wx.EmptyBitmap(10, 10, -1)
        dc = wx.MemoryDC()
        dc.SelectObject(self.bmp)
        dc.Clear()
        renderer.draw_triangle(dc, [5,5], 10)
    
    def test_all_symbols(self):
        for (symbol, funct) in renderer.symbols.items():
            self.bmp = wx.EmptyBitmap(10, 10, -1)
            dc = wx.MemoryDC()
            dc.SelectObject(self.bmp)
            dc.Clear()
            funct(dc, [5,5], 10)
            
    def tearDown(self):
        pass


if __name__=='__main__':
    class ImageWindow(wx.Window):
        def __init__(self, parent):
            wx.Window.__init__(self, parent)
            self.Bind(wx.EVT_PAINT, self.OnPaint)
        def OnPaint(self, event):
            print "OnPaint"
            bmp = wx.EmptyBitmap(30, 30, -1)
            dc = wx.MemoryDC()
            dc.SelectObject(bmp)
            dc.Clear()
            renderer.draw_triangle(dc, [15,15], size=20)
            cdc = wx.PaintDC(window)
            cdc.DrawBitmap(bmp, 0, 0, True)
            
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, "Test symbol")
    window = ImageWindow(frame)
    frame.Show()
    app.MainLoop()